/**
 * \file I3AddressBook.h
 * \brief This file declares the I3AddressBook class.
 */
 
#ifndef I3_ADDRESSBOOK_H
#define I3_ADDRESSBOOK_H 1

//TODO Convert the Address Book to a C++ class
extern "C" {
    #include "i3.h"
};

#include <string>
#include <vector>
#include <map>
#include <pthread.h>
#include <assert.h>
#include <regex.h>

using namespace std;

class I3AddressBook {

private:
    map<string, string*> map_ID_DNSName;
    map<string,ID*>* addrbook;

    pthread_t      addr_book_refresh_thrd;
    pthread_mutex_t    addr_book_mutex;
    int addr_book_sleeptime;
    time_t check_time;
    
    char addr_book_file_store[200];

    int addr_book_lock_mutex();
    int file_modified();
    ID* find_matching_id(char* server_proxy_name);
    int addr_book_unlock_mutex();
public:

    I3AddressBook(char *filename);
    void init_addrbook(char *filename);
    void init_rulebook();
    ID* lookup_addrbook(const char* i3dns);
    ID *match_rules(char* legacydns);
    char* match_rules_spname(char* legacydns);
    void *addr_book_refresh(void *arg);
    

    string* lookupID(ID id);

};

#define NOREDIRECT 0
#define REDIRECT 1


#endif
